package com.kapo.egroup.handler;

import com.kapo.egroup.common.ResponseEnum;
import com.kapo.egroup.common.Result;
import com.kapo.egroup.exception.CustomerAuthenticationException;
import com.kapo.egroup.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @descriptions 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(value = ServiceException.class)
    public @ResponseBody Result SystemError(ServiceException e)
    {
        logger.info("msg:{}", e.getMessage());
        return Result.fail().msg(e.getMessage());
    }

    @ExceptionHandler(value = CustomerAuthenticationException.class)
    public @ResponseBody Result NotLogin() {
        return Result.ok(ResponseEnum.NOT_LOGIN);
    }

}
